<!--
- File:    花园任务(编辑).
-->
<template>
  <div class="Web_Box" style="margin-bottom: 0">
    <div class="bg_fff">
      <div class="water_cont2 renwu">
        <ul>
          <li>提醒
            <i class="iconfont icon-kaiqi fr set" style="font-size: 30px; line-height: 20px;" v-show="ifNotice == '1'" @click="switchNotice('0')"></i>
            <i class="iconfont icon-guanbi fr" style="font-size: 30px; color:#aaa; line-height: 20px;" v-show="ifNotice == '0'" @click="switchNotice('1')"></i>
          </li>
          <li>时隔天数 <a class="fr set" @click="showIntervalPicker">设置</a><span class="timest fr" v-show="!$utils.empty(interval)">间隔{{interval}}{{intervalType | taskIntervalTxt}}</span>
          </li>
          <li>提醒时间 <a class="fr set" @click="showIntervalTimePicker">设置</a><span class="timest fr">{{intervalTime}}</span>
          </li>
        </ul>
      </div>
      <div class="add_time2 f-cb">
        <input type="text" cl ass="g_ipts" placeholder="请输入任务标题" v-model="title">
      </div>
      <div class="srticle">
        <textarea placeholder="请输入任务内容" v-model="content"></textarea>
      </div>
      <div class="artic_btn f-cb">
        <a class=" bg_a8a8a8" @click="back">取消</a><a class="bg_3dbb6e" @click="updateGardenTask">提交</a></div>
    </div>
    <date-picker ref="intervalPicker" @confirm="changeInterval"></date-picker>
    <time-picker ref="intervalTimePicker" @confirm="changeTimeInterval"></time-picker>
  </div>
</template>

<script>
  import DatePicker from '../../../components/datePicker'
  import TimePicker from '../../../components/timePicker'

  export default{
    data() {
      return {
        gardenId: this.$route.params.id,
        title: '',
        content: '',
        ifNotice: '1',
        interval: '',
        intervalType: '',
        intervalTime: ''
      }
    },
    components: {
      'date-picker': DatePicker,
      'time-picker': TimePicker
    },
    created() {
      this.getGardenTaskInfo()
    },
    methods: {
      back() {
        this.$router.go(-1)
      },
      switchNotice(value) {
        this.ifNotice = value
      },
      showIntervalPicker() {
        this.$refs.intervalPicker.open()
      },
      showIntervalTimePicker() {
        this.$refs.intervalTimePicker.open()
      },
      getGardenTaskInfo() {
        this.$request.getGardenTaskInfo(this.gardenId).then(data => {
          this.title = data.ta_title
          this.content = data.ta_note
          this.ifNotice = data.is_tip
          this.interval = data.ta_interval
          this.intervalType = data.ta_interval_type
          this.intervalTime = data.ta_time
        })
      },
      updateGardenTask() {
        if (this.ifNotice == '') {
          this.$toast('请选择是否提醒')
          return
        }
        if (this.interval == '') {
          this.$toast('请输入时隔天数')
          return
        }
        if (this.intervalTime == '') {
          this.$toast('请输入提醒时间')
          return
        }
        if (this.title == '') {
          this.$toast('请输入标题')
          return
        }
        if (this.content == '') {
          this.$toast('请输入内容')
          return
        }
        let param = {
          g_id: this.gardenId,
          is_tip: this.ifNotice,
          ta_interval: this.interval,
          ta_interval_type: this.intervalType,
          ta_note: this.content,
          ta_time: this.intervalTime,
          ta_title: this.title
        }
        this.$request.updateGardenTask(param).then(data => {
          this.$toast('提交成功')
          this.$router.go(-1)
        })
      },
      changeInterval(value) {
        console.log(value)
        let interval = value[0]
        let intervalType
        switch (value[1]) {
          case '天':
            intervalType = '1'
            break
          case '周':
            intervalType = '2'
            break
          case '月':
            intervalType = '3'
            break
          case '年':
            intervalType = '4'
            break
        }
        this.interval = interval
        this.intervalType = intervalType
      },
      changeTimeInterval(value) {
        let time = value[0] + ':' + value[1]
        this.intervalTime = time
      }
    }
  }
</script>

<style>

</style>